<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['covers']) && (($_SESSION['covers']&1<<1) == 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$intCoverId		= $objRequest->getParam('pcoverid', '');
$intUserId		= $objRequest->getParam('puserid', '');
$strName		= $objRequest->getParam('pname', '');
$intDisorder	= $objRequest->getParam('pdisorder', 0);
$strReferSuc	= $objRequest->getParam('prefer','');
$strReferUnsuc	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : (HOST_BACKEND . 'cover/edit?coverid=' . $intCoverId);
$oFile			= $_FILES['pimage'];
$strImage		= '';
$intError		= 0;
if($strName == '') $intError = 2;
elseif($strName != '' && strlen($strName) < 2) $intError = 3;
if($intError == 0 && $oFile['name'] != '') {
	$arrImage	= Vfriend_Upload::uploadCover($oFile, $strImage);
	if($arrImage['error'] > 0) {
		$intError = 5;
	}
} 
if($intError == 0) {
	if(isset($_SESSION['copost'])) unset($_SESSION['copost']);
	if(isset($_SESSION['coerr'])) unset($_SESSION['coerr']);
	$objCover = new Cover();
	$intError = $objCover->update($AppUI->id,$intUserId,$intCoverId,$strName,$strImage,$intDisorder);
	if($intError == 0) {
		Vfriend_Function::redirect($strReferSuc);
	}
} 
if($intError > 0) {
	$strError			= $arrError[$intError];
	$_SESSION['copost'] = $this->getParams();
	$_SESSION['coerr']	= $strError;	
	Vfriend_Function::redirect($strReferUnsuc);
}

?>